﻿using System;
using System.Collections.Generic;

namespace YArchitech.Plumbing
{
	public class HYPipeCal : HYPlumbingObject
	{
		public void Init()
		{
			this.endBathroom = null;
			this.endFire = null;
			this.valveArray.Clear();
			this.fittingArray.Clear();
			this.subPipeArray.Clear();
		}

		public double Equivalent(HYSystemCal.SystemType sType)
		{
			this.dEquivalent = 0.0;
			foreach (HYBathroom hybathroom in this.upBathroomArray)
			{
				if (sType == HYSystemCal.SystemType.Drainage)
				{
					this.dEquivalent += hybathroom.dFluxEquivalent;
				}
				else if (sType == HYSystemCal.SystemType.Feed)
				{
					this.dEquivalent += hybathroom.dSupplyEquivalent;
				}
			}
			return this.dEquivalent;
		}

		public void AddSubPipe(HYPipeCal pipe)
		{
			if (pipe == null)
			{
				return;
			}
			if (!this.subPipeArray.Contains(pipe))
			{
				this.subPipeArray.Add(pipe);
				pipe.perviousPipe = this;
			}
		}

		public void AddFitting(HYFittingCal fit)
		{
			if (fit == null)
			{
				return;
			}
			if (this.fittingArray.Contains(fit))
			{
				return;
			}
			this.fittingArray.Add(fit);
			fit.attachPipe = this;
		}

		public void AddValve(HYPipeValveCal valve)
		{
			if (valve == null)
			{
				return;
			}
			if (this.valveArray.Contains(valve))
			{
				return;
			}
			this.valveArray.Add(valve);
			valve.attachPipe = this;
		}

		public void GetDNFromArray()
		{
			if (this.dirDNArray == null || this.dirDNArray.Count <= 0)
			{
				return;
			}
			int key = this.nDN;
			foreach (KeyValuePair<int, double> keyValuePair in this.dirDNArray)
			{
				if (this.nDN <= keyValuePair.Key)
				{
					this.nDN = keyValuePair.Key;
					return;
				}
				key = keyValuePair.Key;
			}
			this.nDN = key;
		}

		public double GetInDN()
		{
			double result = -1.0;
			if (this.dirDNArray == null || this.dirDNArray.Count <= 0)
			{
				return result;
			}
			foreach (KeyValuePair<int, double> keyValuePair in this.dirDNArray)
			{
				result = keyValuePair.Value;
				if (this.nDN <= keyValuePair.Key)
				{
					return result;
				}
			}
			return result;
		}

		public HYBathroom endBathroom;

		public HYSprinklerCal endSprinkler;

		public HYFire endFire;

		public List<HYBathroom> upBathroomArray = new List<HYBathroom>();

		public List<HYPipeValveCal> valveArray = new List<HYPipeValveCal>();

		public List<HYFittingCal> fittingArray = new List<HYFittingCal>();

		public List<HYPipeCal> subPipeArray = new List<HYPipeCal>();

		public HYPipeCal perviousPipe;

		public bool bIsHorL;

		public bool bIsOutPipe;

		public double dFullness;

		public double dGrad;

		public string szMaterial;

		public double dEquivalent;

		public Dictionary<int, double> dirDNArray = new Dictionary<int, double>();

		public double dLostWator;

		public double dCs;

		public double FlowN;

		public int nDN;

		public int MinDN;

		public string szNote;

		public bool bIsCal = true;

		public HYSprayNode startNode;

		public HYSprayNode endNode;

		public double startPress;

		public bool bIsStart;

		public int iPathNum = -1;

		public int nStartNum;

		public int nEndNum;

		public enum DrainType
		{
			Exhaust,
			Riser,
			Hori
		}
	}
}
